﻿#include <iostream>
#include <map>
#include <vector>
#include <ctime>
using namespace std;
#define CEHUA 0
#define MEISHU 1
#define YANFA 2
class Worker 
{
public :
	string m_Name;
	int m_Salary;
};
void CreatWorker(vector<Worker>& v)
{
	string nameSeed = "ABCDEFGHIJ";
	for (int i = 0; i < 10; i++)
	{
		Worker worker;
		worker.m_Name = "员工";
		worker.m_Name += nameSeed[i];
		worker.m_Salary = rand() % 10000 + 10000;
		v.push_back(worker); 
	}
}
void SetGroup(vector<Worker>& v, multimap<int, Worker>& m)
{
	for (vector<Worker>::iterator it = v.begin(); it != v.end(); it++)
	{
		//产生随机部门编号
		int depId = rand() % 3;
		//将员工插入到分组中
		m.insert(make_pair(depId, *it));
	}
}
void ShowWorker(multimap<int, Worker>& m)
{
	cout << "策划部的信息:" << endl;
	multimap<int,Worker>::iterator it=m.find(CEHUA);
	int count = m.count(CEHUA);
	int index = 0;
	for (; it != m.end()&&index<count; it++,index++)
	{
		cout << it->second.m_Name << "   工资为:" << it->second.m_Salary << endl;
	}
	cout << endl;
	cout << "美术部的信息:" << endl;
	it = m.find(MEISHU);
	count = m.count(MEISHU);
	index = 0;
	for (; it != m.end() && index < count; it++, index++)
	{
		cout << it->second.m_Name << "   工资为:" << it->second.m_Salary << endl;
	}
	cout << endl;
	cout << "研发部的信息:" << endl;
	it = m.find(YANFA);
	count = m.count(YANFA);
	index = 0;
	for (; it != m.end() && index < count; it++, index++)
	{
		cout << it->second.m_Name << "   工资为:" << it->second.m_Salary << endl;
	}
}
int main()
{
	//随机数种子
	srand((unsigned int)time(NULL));
	//1.创建员工
	vector<Worker>v;
	CreatWorker(v);
	//员工分组
	multimap<int, Worker> mworker;
	SetGroup(v,mworker);
	//分组显示员工
	ShowWorker(mworker);
	//测试
	//for (vector<Worker>::iterator it = v.begin(); it != v.end(); it++)
	//{
	//	cout << it->m_Name << "   " << "工资为:" << it->m_Salary << endl;
	//}
}